<!-- 发起演练 -->
<template>
	<view class="page">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block style="color: #777777;font-size: 32rpx;" slot="content">发起演练</block>
		</cu-custom>
 
		<view class="cu-form-group margin-top">
			<view class="title">区域名称</view>
			<picker  @change="bindPickerChange($event,array)" :value="index"
				:range="array" range-key="name">
				<view class="input">
					{{index>-1?array[index].name:'请选择区域名称'}}
				</view>
			</picker>
		</view>
		
		<view class="cu-form-group margin-top">
			<view class="title">是否联动周边力量</view>
			<radio-group @change="radioZbllChange">
				<label class="radio" style="margin-right: 30rpx;">
					<radio value="1" />是
				</label>
				<label class="radio">
					<radio value="0" checked="true" />否
				</label>
			</radio-group>
		</view>
		<view class="cu-form-group margin-top">
			<view class="title">是否联动警务站</view>
			<radio-group @change="radioJwzChange">
				<label class="radio" style="margin-right: 30rpx;">
					<radio value="1" />是
				</label>
				<label class="radio">
					<radio value="0" checked="true" />否
				</label>
			</radio-group>
		</view>
		<view class="cu-form-group margin-top">
			<view class="title">是否联动消防力量</view>
			<radio-group @change="radioGlbmChange">
				<label class="radio" style="margin-right: 30rpx;">
					<radio value="1" />是
				</label>
				<label class="radio">
					<radio value="0" checked="true" />否
				</label>
			</radio-group>
		</view>
		<view class="cu-form-group margin-top">
			<view class="title">详细地址</view>
			<input v-model="address" placeholder="请输入详细地址" name="address"></input>
		</view>

		<view class="padding flex flex-direction">
			<button class="cu-btn margin-tb-sm lg my-btn" @click="submit">发送通知</button>

		</view>
		<message />
	</view>
</template>

<script>
	export default {
		onLoad() {
			this.getCate()
		},
		data() {
			return {
				index: -1,
				array: [],
				name: '请选择',
				data: [],
				childArr: [], // 二级分类数据源
				lastObj: null,
				title: '',
				address: '',
				zbll: 0,
				jwz: 0,
				glbm: 0
			}
		},
		methods: {
			radioZbllChange(evt) {
				this.zbll = parseInt(evt.detail.value)
			},
			radioJwzChange(evt) {
				this.jwz = parseInt(evt.detail.value)
			},
			radioGlbmChange(evt) {
				this.glbm = parseInt(evt.detail.value)
			},
			getCate() {
				let that = this
				let app = getApp()
				app.globalData.request({
					url: 'wx/fireInfo/getSubfieldRegionList',
					data: {

					}
				}).then(function(res) {
					console.info(res.data.data)
					that.array = res.data.data


				}).catch(function(e) {
					console.info("e:", e)
				})
			},

			// 选择任务分类
			bindPickerChange: function(e, storage) {
				this.index = e.target.value
				this.lastObj = storage[this.index] // 这里就是选中的对象

			},
			submit() {
				let params = {
					"location": this.address,
					"ucId": this.lastObj.ucId,
					"regionName": this.lastObj.name,
					"zbll": this.zbll,
					"jwz": this.jwz,
					"glbm": this.glbm
				}
				let app = getApp()
				app.globalData.request({
					url: '/wx/fireInfo/drillNotice',
					data: params
				}).then(function(res) {
					console.log(res)
					let data = res.code
					if (data == 0) {
						uni.showToast({
							title: "发起演练成功"
						})
						uni.navigateBack({
							delta: 2
						});
					} else {
						uni.showToast({
							title: res.data.msg
						})
					}

				}).catch(function(e) {
					uni.showToast({
						title: '该区域没有巡检'
					})
				})
			},
		}

	}
</script>

<style scoped>
	.my-btn {
		height: 94rpx;
		margin-top: 80px;
		background-image: linear-gradient(90deg, #FAB53A 4%, #EFA21A 99%);
		box-shadow: 0 0 12px 0 rgba(250, 181, 58, 0.50);
		border-radius: 24px;
		ont-family: PingFangSC-Medium;
		color: #FFFFFF;
		letter-spacing: 0;
		text-align: center;
	}
</style>
